{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import display, HTML\n",
    "import pandas as pd\n",
    "import json\n",
    "import requests\n",
    "key = \"a9454b6e9de52eded7e025431684c2fb\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "def search(keywords,datatype,location=None,type=None,city=None,citylimit=None,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/assistant/inputtips?parameters'\n",
    "    params={\n",
    "        'key':key,\n",
    "        'keywords':keywords,\n",
    "        'location':location,\n",
    "        'type':type,\n",
    "        'city':city,\n",
    "        'citylimit':citylimit,\n",
    "        'datatype':datatype,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '10',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'tips': [{'id': 'B03DF0S5GM',\n",
       "   'name': '肯德基(中山路店)',\n",
       "   'district': '新疆维吾尔自治区乌鲁木齐市天山区',\n",
       "   'adcode': '650102',\n",
       "   'location': '87.616293,43.794344',\n",
       "   'address': '中山路297号',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B02B30LZZS',\n",
       "   'name': '肯德基(西双十二城店)',\n",
       "   'district': '云南省西双版纳傣族自治州景洪市',\n",
       "   'adcode': '532801',\n",
       "   'location': '100.805775,22.004311',\n",
       "   'address': '勐海路2号西双十二城大润发1层',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B03A305576',\n",
       "   'name': '肯德基(新亚欧店)',\n",
       "   'district': '甘肃省兰州市城关区',\n",
       "   'adcode': '620102',\n",
       "   'location': '103.818860,36.059668',\n",
       "   'address': '中山路120号亚欧商厦1层',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B03A30AZK8',\n",
       "   'name': '肯德基(火车站店)',\n",
       "   'district': '甘肃省兰州市城关区',\n",
       "   'adcode': '620102',\n",
       "   'location': '103.852084,36.034781',\n",
       "   'address': '兰州火车站',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B036705IXH',\n",
       "   'name': '肯德基(青年路店)',\n",
       "   'district': '云南省昆明市五华区',\n",
       "   'adcode': '530102',\n",
       "   'location': '102.715481,25.041656',\n",
       "   'address': '人民中路17号百盛购物广场1层',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B036705OGR',\n",
       "   'name': '肯德基(山姆店)',\n",
       "   'district': '云南省昆明市官渡区',\n",
       "   'adcode': '530111',\n",
       "   'location': '102.730680,25.013201',\n",
       "   'address': '春城路289号沃尔玛购物广场1层',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B001C7ZY8Y',\n",
       "   'name': '肯德基(温江DT店)',\n",
       "   'district': '四川省成都市温江区',\n",
       "   'adcode': '510115',\n",
       "   'location': '103.855564,30.688456',\n",
       "   'address': '光华大道三段1888号',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B0FFFABSC6',\n",
       "   'name': '肯德基(杭州路店)',\n",
       "   'district': '四川省眉山市东坡区',\n",
       "   'adcode': '511402',\n",
       "   'location': '103.831395,30.054106',\n",
       "   'address': '三苏大道168号',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B0FFFACQIG',\n",
       "   'name': '肯德基(环湖店)',\n",
       "   'district': '四川省眉山市东坡区',\n",
       "   'adcode': '511402',\n",
       "   'location': '103.845948,30.045129',\n",
       "   'address': '环湖东段100号大润发1楼',\n",
       "   'typecode': '050301',\n",
       "   'city': []},\n",
       "  {'id': 'B001C80FFL',\n",
       "   'name': '肯德基(簇桥店)',\n",
       "   'district': '四川省成都市武侯区',\n",
       "   'adcode': '510107',\n",
       "   'location': '103.990533,30.607304',\n",
       "   'address': '簇桥簇锦北路138号千盛生活广场1楼',\n",
       "   'typecode': '050301',\n",
       "   'city': []}]}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>status</th>\n",
       "      <th>count</th>\n",
       "      <th>info</th>\n",
       "      <th>infocode</th>\n",
       "      <th>tips</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>{'id': 'B03DF0S5GM', 'name': '肯德基(中山路店)', 'dis...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>{'id': 'B02B30LZZS', 'name': '肯德基(西双十二城店)', 'd...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>{'id': 'B03A305576', 'name': '肯德基(新亚欧店)', 'dis...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>{'id': 'B03A30AZK8', 'name': '肯德基(火车站店)', 'dis...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>{'id': 'B036705IXH', 'name': '肯德基(青年路店)', 'dis...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>{'id': 'B036705OGR', 'name': '肯德基(山姆店)', 'dist...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>{'id': 'B001C7ZY8Y', 'name': '肯德基(温江DT店)', 'di...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>{'id': 'B0FFFABSC6', 'name': '肯德基(杭州路店)', 'dis...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>{'id': 'B0FFFACQIG', 'name': '肯德基(环湖店)', 'dist...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>{'id': 'B001C80FFL', 'name': '肯德基(簇桥店)', 'dist...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  status count info infocode  \\\n",
       "0      1    10   OK    10000   \n",
       "1      1    10   OK    10000   \n",
       "2      1    10   OK    10000   \n",
       "3      1    10   OK    10000   \n",
       "4      1    10   OK    10000   \n",
       "5      1    10   OK    10000   \n",
       "6      1    10   OK    10000   \n",
       "7      1    10   OK    10000   \n",
       "8      1    10   OK    10000   \n",
       "9      1    10   OK    10000   \n",
       "\n",
       "                                                tips  \n",
       "0  {'id': 'B03DF0S5GM', 'name': '肯德基(中山路店)', 'dis...  \n",
       "1  {'id': 'B02B30LZZS', 'name': '肯德基(西双十二城店)', 'd...  \n",
       "2  {'id': 'B03A305576', 'name': '肯德基(新亚欧店)', 'dis...  \n",
       "3  {'id': 'B03A30AZK8', 'name': '肯德基(火车站店)', 'dis...  \n",
       "4  {'id': 'B036705IXH', 'name': '肯德基(青年路店)', 'dis...  \n",
       "5  {'id': 'B036705OGR', 'name': '肯德基(山姆店)', 'dist...  \n",
       "6  {'id': 'B001C7ZY8Y', 'name': '肯德基(温江DT店)', 'di...  \n",
       "7  {'id': 'B0FFFABSC6', 'name': '肯德基(杭州路店)', 'dis...  \n",
       "8  {'id': 'B0FFFACQIG', 'name': '肯德基(环湖店)', 'dist...  \n",
       "9  {'id': 'B001C80FFL', 'name': '肯德基(簇桥店)', 'dist...  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "results = search(keywords='肯德基',datatype=all)\n",
    "display(results)\n",
    "dataframe = pd.DataFrame ( results )\n",
    "display(dataframe)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
